package com.oreilly.learningsparkexamples.scala

import org.apache.spark._

object WordCount {
  def main(args: Array[String]): Unit = {
    val inputfile = args(0)
    val outputfile = args(1)
    val conf = new SparkConf()
      .setAppName("WordCount")
    val sc = new SparkContext(conf)
    val input = sc.textFile(inputfile)
    val words = input.flatMap(line => line.split(" "))
    val counts = words.map(word => (word,1)).reduceByKey{ case(x,y) => x+y }
    counts.saveAsTextFile(outputfile)
  }
}